package image_utils

import (
	"image/color"
	"math"
)

// colorDistance 计算两个颜色之间的欧氏距离
func ColorDistance(c1, c2 color.Color) float64 {
	r1, g1, b1, _ := c1.RGBA()
	r2, g2, b2, _ := c2.RGBA()
	rDiff := float64(r1) - float64(r2)
	gDiff := float64(g1) - float64(g2)
	bDiff := float64(b1) - float64(b2)
	return math.Sqrt(rDiff*rDiff + gDiff*gDiff + bDiff*bDiff)
}

// isColorSimilar 判断两个颜色是否相近
func isColorSimilar(c1, c2 color.Color, threshold float64) bool {
	return ColorDistance(c1, c2) < threshold
}
